#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;

int n, m, t;
ll r[N], c[N];
ll sum[N];
ll solve(ll a[N], int n, int avg) {
  rep(i, 1, n) a[i] += a[i - 1] - avg;
  sort(a + 1, a + n + 1);
  int j = (n + 1) / 2;
  ll res = 0;
  rep(i, 1, n) res += abs(a[i] - a[j]);
  return res;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m >> t;
  rep(i, 1, t) {
    int x, y;
    cin >> x >> y;
    r[x]++, c[y]++;
  }
  if (t % n && t % m) {
    cout << "impossible";
    return 0;
  } else if (t % n == 0 && t % m == 0)
    cout << "both ";
  else if (t % n == 0)
    cout << "row ";
  else
    cout << "column ";
  ll cnt = 0;
  if (t % n == 0) cnt += solve(r, n, t / n);
  if (t % m == 0) cnt += solve(c, m, t / m);
  cout << cnt;
  return 0;
}